package Top_Interview_Questions.Bit_Manipulation;

/**
 * @Author: 吕庆龙
 * @Date: 2020/2/1 12:47
 * <p>
 * 功能描述:
 */
public class _0191 {

    public static void main(String[] args) {
        _0191 test = new _0191();
        int num1 = 11;
        System.out.println(test.hammingWeight(num1));
    }

    public int hammingWeight(int n) {
        int count = 0;
        int flag = 1;
        for (int i = 0; i < 32; i++) {
            if ((n & flag) == 1){
                count++;
            }
            n = n >> 1;
        }
        return count;
    }
}
